package mock.action;
import com.opensymphony.xwork2.ActionSupport;
import mock.dao.*;
import mock.model.*;
public class LoginAction extends ActionSupport{
	private String account;
	private String password;
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public String checkLogin(){
		if(account == null || account.trim().length() == 0){
			addActionError(getText("username.required"));
			return ERROR;
		}
		if(password == null || password.trim().length() == 0){
			addActionError(getText("password.required"));
			return ERROR;
		}
		if(password.trim().length() < 6){
			addActionError(getText("password.invalidLength"));
			return ERROR;
		}
		User user = new User();
		user.setAccount(account);
		user.setPassword(password);
		UserDAO userDao = new UserDAO();
		
		if(userDao.checkLogin(user))
			return SUCCESS;
		else{
			addActionError(getText("login.error"));
			return ERROR;
		}	
	}
	
	public String getUserName() {
		return account;
	}
	public void setUserName(String account) {
		this.account = account;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public static long getSerialversionuid() {
		return serialVersionUID;
	}
}
